package com.tianwu.lbsdatabasedesign;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Tianwu on 2016/7/5.
 */
public class Database extends SQLiteOpenHelper {

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "lbs_database_design.db";

    public static final String TABLE_NAME = "trace_loction";
    public static final String CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    MyLocation.TIME + " TEXT PRIMARY KEY," +
                    MyLocation.ADDRESS + " TEXT," +
                    MyLocation.LATITUDE + " DOUBLE," +
                    MyLocation.LONGITUDE + " DOUBLE" +
                    ");";
    public static final String DELETE_TABLE = "" +
            "DROP TABLE IF EXISTS " + TABLE_NAME;

    public Database(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE);
    }
    @Override
    public void onOpen(SQLiteDatabase db){
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // This database is only a cache for online data, so its upgrade policy is
        // to simply to discard the data and start over
        db.execSQL(DELETE_TABLE);
        onCreate(db);
    }
    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }
}
